package com.sanyue.codingsettlement.mqstudy.rabbitmq.deadLetter;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DeliverCallback;

/**
 * @author: Guan
 **/
public class DeadLetterConsumer {
    public static void main(String[] args) throws Exception{
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        //声明
        channel.exchangeDeclare("some.exchange.name", "direct");
        channel.queueDeclare("dead_letter_queue",false,false,false,null);
        channel.queueBind("dead_letter_queue", "some.exchange.name", "dead");
        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
            System.out.println("死信队列接收到消息");
        };

        //接收消息
        channel.basicConsume("dead_letter_queue", true, deliverCallback, consumerTag -> { });
    }
}
